<template>
  <div class="td-update-password">
    <mt-header fixed title="修改密码">
      <router-link to="tdSetting" slot="left">
        <mt-button icon="back"></mt-button>
      </router-link>
    </mt-header>

    <mt-field label="旧密码" placeholder="请输入旧密码" v-model="params.OldPwd"></mt-field>
    <mt-field label="新密码" placeholder="请输入新密码" v-model="params.NewPwd"></mt-field>
    <mt-field label="重复密码" placeholder="请输入重复密码" v-model="params.RepNewPwd"></mt-field>
    <div class="btnSubmit">
      <el-button
        type="primary"
        class="td-btn-patient-primary"
        @click="btnSave();"
        style="width:80%;"
        round
      >修改</el-button>
    </div>
  </div>
</template>

<script>
import UserService from "../../../../_services/user.service";
export default {
  name: "TianDingPatientMeUpdatePasswordComponent",
  data() {
    return {
      params: {
        UserID: 0,
        NewPwd: "",
        RepNewPwd: "",
        OldPwd: ""
      }
    };
  },
  methods: {
    btnSave() {
      if (!this.utils$.isEmpty(this.params.OldPwd)) {
        this.toast$("请输入旧密码");
        return;
      }

      if (!this.utils$.isEmpty(this.params.NewPwd)) {
        this.toast$("请输入新密码");
        return;
      }

      if (!this.utils$.isEmpty(this.params.RepNewPwd)) {
        this.toast$("请输入重复密码");
        return;
      }

      if (this.params.NewPwd !== this.params.RepNewPwd) {
        this.toast$("两次输入密码不一致");
        return;
      }

      this.indicator$.open("请稍后...");

      let user = JSON.parse(this.local$.getItem("tdUser"));
      this.params.UserID = user.UserID;

      UserService.updatePassword(this.params).then(response => {
        if (response.Data > 0) {
          this.toast$("修改成功");
        } else {
          this.toast$("修改失败");
        }
        this.params.UserID = 0;
        this.params.OldPwd = "";
        this.params.NewPwd = "";
        this.params.RepNewPwd = "";
        this.indicator$.close();
      });
    }
  }
};
</script>

